package com.ruoyi.schoolSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.schoolSys.model.vo.AskLeaveVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.schoolSys.domain.AskLeave;
import com.ruoyi.schoolSys.service.IAskLeaveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 请假管理Controller
 * 
 * @author ruoyi
 * @date 2024-02-19
 */
@RestController
@RequestMapping("/schoolSys/askLeave")
public class AskLeaveController extends BaseController
{
    @Autowired
    private IAskLeaveService askLeaveService;

    /**
     * 查询请假管理列表
     */
    @PreAuthorize("@ss.hasPermi('schoolSys:askLeave:list')")
    @GetMapping("/list")
    public TableDataInfo list(AskLeave askLeave)
    {
        startPage();
        List<AskLeaveVo> list = askLeaveService.selectAskLeaveList(askLeave);
        return getDataTable(list);
    }

    /**
     * 导出请假管理列表
     */
    @PreAuthorize("@ss.hasPermi('schoolSys:askLeave:export')")
    @Log(title = "请假管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AskLeave askLeave)
    {
        List<AskLeaveVo> list = askLeaveService.selectAskLeaveList(askLeave);
        ExcelUtil<AskLeaveVo> util = new ExcelUtil<AskLeaveVo>(AskLeaveVo.class);
        util.exportExcel(response, list, "请假管理数据");
    }

    /**
     * 获取请假管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('schoolSys:askLeave:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(askLeaveService.selectAskLeaveById(id));
    }

    /**
     * 新增请假管理
     */
    @PreAuthorize("@ss.hasPermi('schoolSys:askLeave:add')")
    @Log(title = "请假管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AskLeave askLeave)
    {
        return toAjax(askLeaveService.insertAskLeave(askLeave));
    }

    /**
     * 修改请假管理
     */
    @PreAuthorize("@ss.hasPermi('schoolSys:askLeave:edit')")
    @Log(title = "请假管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AskLeave askLeave)
    {
        return toAjax(askLeaveService.updateAskLeave(askLeave));
    }

    /**
     * 删除请假管理
     */
    @PreAuthorize("@ss.hasPermi('schoolSys:askLeave:remove')")
    @Log(title = "请假管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(askLeaveService.deleteAskLeaveByIds(ids));
    }
}
